package com.itheima.server.controller;


import com.itheima.server.service.SmallVideosService;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideoController {

    @Autowired
    private SmallVideosService videosService;

    /**
     * 接口名称：视频上传
     * 接口路径：POST/smallVideos
     */
    @PostMapping
    public ResponseEntity saveVide(MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException{
        videosService.saveVideo(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }

    /**
     * 视频列表
     */
    @GetMapping
    public ResponseEntity queryVideoList(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult result = videosService.queryVideoList(page,pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 接口名称：视频用户关注
     * 接口路径：POST/smallVideos/:uid/userFocus
     */
    @PostMapping("{uid}/userFocus")
    public ResponseEntity queryVideoList(@PathVariable("uid") Long followUserId){
        videosService.userFocus(followUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 接口名称：取消关注用户关注
     * 接口路径：POST/smallVideos/:uid/userFocus
     */
    @PostMapping("{id}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("id") Long followUserId){
        videosService.userUnFocus(followUserId);
        return ResponseEntity.ok(null);
    }

}